import subprocess
from pathlib import Path


def is_video_corrupted(video_path):
    try:
        probe = subprocess.check_output(['ffprobe', '-v', 'error', '-show_entries', 'stream=codec_type', '-of',
                                         'default=noprint_wrappers=1:nokey=1', video_path])
        if 'video' in probe.decode('utf-8'):
            return False
        else:
            return True
    except subprocess.CalledProcessError as e:
        print(f"探测视频时出错: {e}")
        return True


root_dir = Path(r"E:\数据恢复\视频")
for video_path in root_dir.glob("**/*.*"):
    if video_path.suffix.lower() in ['.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv', '.mpeg', '.mpg', '.3gp',
                                     '.webm']:  # 添加更多的视频文件扩展名如果需要
        if is_video_corrupted(video_path):
            print(f"{video_path} !!!已损坏!!!.")
